package controller;

import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import pojo.Book;
import pojo.User;

@Controller
@RequestMapping(value="/user")
//@SessionAttributes("u")

public class UserConntroller {
	
	public UserConntroller() {
		
		System.out.println("userController contruct.....");
	}

	@RequestMapping(value={"/a?.do"},method={RequestMethod.GET},consumes="application/json",produces="application/json",params="id=1")
	public String login(){
		System.out.println("login.....");
		return "suc";
	}
	@RequestMapping(value={"/login"},method={RequestMethod.GET},headers="Content-Type=text/html")
	public String login1(){
		System.out.println("login1.....");
		return "suc";
	}
	@RequestMapping("/regist")
	public String regist(User u,@CookieValue(value="JSENSSIONID") String ID){
		System.out.println(u.getUname()+"...."+u.getAge());
		System.out.println(ID);
		return "suc";
		
	}
	@RequestMapping(value="regist1")
	@ResponseBody
	public User regist1(@RequestBody User u){
		return u;
	}
	
	@RequestMapping("/addBook")
	@ResponseBody
	public Book addBook(@RequestBody Book b,@ModelAttribute("uu") User u){
		b.setId((int)(Math.random()*100));
		return b;
	}
	@ModelAttribute("bean")
	public String getBean(){
		System.out.println("getBean.....");
		return "coffee bean!!!";
	}
	
	@RequestMapping("/pet/{petid}/cup/{cupid}")
	public String test11(@PathVariable String petid,@PathVariable int cupid,HttpServletRequest req,HttpSession sen,
			HttpServletResponse resp,Model model){
		
		System.out.println(req);
		System.out.println(req.getSession().getServletContext().getRealPath("/"));
		
		System.out.println(petid+"....."+cupid);
		model.addAttribute("uname", "johnYu");
		return "suc";
	}
	
	
	
	
	
	
	
	
	
	
	
}
